export type TodoItemType = {
    id: number,
    title: string,
    completed: boolean,
    description: string
}

export async function getTodoListAPI(formData: {
    listLenth: number,
    isError: boolean,
    delay: number
}): Promise<TodoItemType[]> {
    if (formData.isError) {
        return Promise.reject(new Error('请求错误'))
    }
    let list: TodoItemType[] = []
    for (let i = 0; i < formData.listLenth; i++) {
        list.push({
            id: Math.floor(Math.random() * 1000),
            title: `第 ${i + 1} 个任务`,
            completed: Math.random() > 0.5,
            description: `这是第 ${i + 1} 个任务的描述。`
        })
    }
    console.log('delay:', formData.delay)
    await new Promise(resolve => setTimeout(resolve, formData.delay))
    return Promise.resolve(list)
}

export async function getTodoListSimpleAPI(): Promise<TodoItemType[]> {
    return await getTodoListAPI({
        listLenth: Math.floor(Math.random() * 10) + 5,  // 列表长度: 5-15
        isError: false,
        delay: Math.floor(Math.random() * 3000) + 50
    }) 
}